package com.Lixiaoqian.CardPlay.adapter;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.Lixiaoqian.CardPlay.R;
import com.Lixiaoqian.CardPlay.bean.NavItemBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by HuangZhiBo on 2017/3/31/031.
 */

public class NavAdapter extends BaseAdapter {
    private ArrayList<NavItemBean> data;
    private Context context;

    public NavAdapter(ArrayList<NavItemBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_navition, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        int image = data.get(position).getImage();
        viewHolder.navIv.setImageResource(image);
        viewHolder.navTitle.setText(data.get(position).getInfo());
        return convertView;
    }


    class ViewHolder {
        @BindView(R.id.nav_iv)
        ImageView navIv;
        @BindView(R.id.nav_title)
        TextView navTitle;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
